{extend name="public/base"/}
{block name="content"}


<div class="layui-col-md12">

    <div class="layui-card">
        <div class="layui-card-body layui-row ">

            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">
                    <div class="layui-inline">
                        <label class="layui-form-label">钩子搜索：</label>
                        <div class="layui-input-inline">
                            <input name="name" class="layui-input" value="" type="text" placeholder="请输入钩子名称">
                        </div>
                    </div>

                    <div class="layui-inline" style="padding-left: 20px;">
                        <button class="layui-btn icon-btn layui-btn-sm"  lay-filter="search" lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" onclick="javascript:window.location.reload();">
                            <i class="layui-icon layui-icon-refresh"></i> 重置
                        </button>
                    </div>

                </div>

            </form>

        </div>

    </div>


    <div class="layui-card">
        <div class="layui-card-body">
            <!--表格区-->
            <div class="yys-fluid yys-wrapper">
                <div class="layui-row lay-col-space20">
                    <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                        <section class="yys-body">
                            <div class="yys-body-content clearfix changepwd">
                                <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                    <div class="user-tables">
                                        <table id="tableFilter" lay-filter="tableFilter"> </table>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>


{/block}


{block name="js"} <!--js处理区-->


<!--模板-->
<script type="text/html" id="operationTpl">

    {:widget('common/forms/Editbtn',array('编辑钩子信息'))}
    {:widget('common/forms/Delbtn',array('删除钩子',2))}

</script>

<script type="text/html" id="status">
    {{# if(d.status==0){  }}
    <span class="layui-badge layui-bg-black">不启用</span>
    {{# }else{ }}
    <span class="layui-badge layui-bg-blue">启用</span>
    {{# } }}

</script>


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon"></i>新增钩子</button>
        <button class="layui-btn layui-btn-danger layui-btn-sm"  lay-event="del"><i class="layui-icon "></i>删除</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="reload"><i class="fa fa-refresh"></i> 刷新</button>
        <button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="ok">启用</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="bind">禁用</button>
    </div>
</script>

<script>

    layui.use(['element', 'table', 'form', 'jquery', 'lucky'], function () {
        let element = layui.element;
        let form = layui.form;
        let table = layui.table;
        let $ = layui.jquery;
        let lucky=layui.lucky;

        form.render();

        // layer.load(2);
        table.render({
            elem: '#tableFilter',
            url:"{:url('hooks')}",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            even: true, //开启隔行背景
            defaultToolbar: ['filter', 'print'],
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:30
                ,limits:[20,30,50,60]
            },
            // height: 'full-100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {type: 'checkbox'},
                {field: 'id',style:'cursor: pointer;',title: 'ID',width:80},
                {field: 'name',style:'cursor: pointer;',title: '钩子名称',width:200},
                {field: 'description', title: '钩子描述', minWidth: 180, style:'cursor: pointer;', templet:function (d) {
                        return '<font  onmouseover="tis(this)" data-title="'+d.description+'">'+d.description+'</font>'
                    }},
                {field:'status',title:'状态',templet: '#status',width:110 ,unresize: true},
                {field: 'type',style:'cursor: pointer;',title: '类型',width:120,templet:function (d) {
                        if (d.type==1){
                            k="视图";
                        }else if(d.type=2){
                            k="控制器";
                        }else {
                            k="未知";
                        }
                        return k;
                    }},
                {field:'addons',title:'关联插件',width:150 },

                {field: 'create_time', title: '添加时间',align: 'center',width:160,sort:true},
                {fixed: 'right',templet: '#operationTpl', width: 110, align: 'center', title: '操作'}
            ]]
            ,done: function (res) {
                layer.closeAll('loading');
            }
        });


        /**
         * 表格搜索
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch("table_id",obj.field); //查询
            return false;
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(tableFilter)', function (obj) {
            let data = obj.data;
            // console.log(JSON.stringify(data));
            let _id=parseInt(data.id);
            let layEvent = obj.event;
            if(layEvent==="edit"){
                let urls="/addons/addons/editHook/id/"+_id;
                lucky.CreateForm("编辑钩子信息",'55%','70%',urls,"table_id",0);

            }else if(layEvent==="del"){
                lucky.Delete_data(_id,"{:url('hookDel')}","table_id");
            }
        });


        //头工具栏事件
        table.on('toolbar(tableFilter)', function(obj){
            let checkStatus = table.checkStatus(obj.config.id);
            let data = checkStatus.data;
            if (obj.event==="add"){
                lucky.CreateForm("添加钩子",'55%','70%',"{:url('addHook')}","table_id",0);
                return  false;
            }else if (obj.event==="del"){
                let num=0;
                let id=[];
                for (let i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                lucky.Delete_data(id,"{:url('hookDel')}",obj.config.id);
                return  false;
            }else if (obj.event==="ok"){
                let num=0;
                let id=[];
                for (let i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                lucky.Delete_data(id,"{:url('hookOk')}",obj.config.id,"确定启用选中的钩子？");
                return  false;
            }else if (obj.event==="bind"){
                let num=0;
                let id=[];
                for (let i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                lucky.Delete_data(id,"{:url('hookFalse')}",obj.config.id,"确定禁用选中的钩子？");
                return  false;
            }
        });

    });

</script >


{/block}


